package com.qfjy.java2102.Controller;

import com.qfjy.java2102.ServiceImpl.LoginServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("pengwei")
public class LoginController {

    @Resource
    private LoginServiceImpl loginService;


    /**
     *
     * @return:进入页面
     */
    @GetMapping("index")
    public String toIndex(){
        return "index";
    }


    /**
     * 核对账号密码，并计算密码错误次数
     * @param username
     * @param password
     * @param request
     * @return
     */
    @GetMapping("check")
    @ResponseBody
    public ResponseBody check(
            @RequestParam(value = "username",required = false)String username,
            @RequestParam(value = "password",required = false)String password,
            HttpServletRequest request
    ){
        String ip=request.getRemoteAddr();
        ResponseBody responseBody = (ResponseBody) loginService.checkUserAndCount(username,password,ip);
        return responseBody;

    }
}
